var preorderTraversal = function (root) {
    // 递归
    let res=[]
    
    const Traversal=(root)=>{
    if(root===null)return null
    res.push(root.val)
    Traversal(root.left)
    Traversal(root.right)
    }
    
    Traversal(root)
    return res
    };
    
    var preorderTraversal = function (root) {
        // 迭代 中左右
        const stack=[root],res=[]
        if(!root)return res
        while(stack.length){
            let node=stack.pop()
            res.push(node.val)
            node.right&&stack.push(node.right)
            node.left&&stack.push(node.left)
        } 
        return res
        };
            